import { result } from 'lodash';
/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-08-11 08:50:44
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-11-25 08:46:34
 */
import { LazyLoadEvent } from 'primeng/api';
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { MessageService } from '@abp/message/message.service';
import { MoadifManageServiceProxy, BomChangeServiceProxy } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
//查看履历
import { BomShowResumeComponent } from './bom-show-resume/bom-show-resume.component';
//新增修改查看
import { BomAddOrEditComponent } from './bom-add-or-edit/bom-add-or-edit.component';
@Component({
    selector: 'app-bom-change',
    templateUrl: './bom-change.component.html',
    styleUrls: ['./bom-change.component.less']
})
export class BomChangeComponent extends AppComponentBase {
    @ViewChild('showResume') ShowResume: BomShowResumeComponent;
    @ViewChild('addOrEddit') addOrEddit: BomAddOrEditComponent;
    @ViewChild('paginator') paginator: Paginator;
    @ViewChild('dataTable') dataTable: Table;
    model = undefined;
    senTime = undefined;
    lotNum = undefined;
    changeType = undefined;
    changeTypeOptions = [
        {
            label: '请选择',
            value: undefined
        }, {
            label: '请选择',
            value: undefined
        }, {
            label: '请选择',
            value: undefined
        },
    ];
    rowdata: any;//子组件传参
    title = undefined;//子组件标题
    saveFlag = true;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _moadifManageServiceProxy: MoadifManageServiceProxy,
        private _bomChangeServiceProxy: BomChangeServiceProxy,
    ) {
        super(injector);
    }
    ngOnInit() {
    }
    selectStatus(value) {
        switch (value) {
            case 0:
                return '编制中';
            case 1:
                return '审核中';
            case 2:
                return '被驳回';
            case 3:
                return '已发布';
            case 4:
                return '已维护';
            case 5:
                return '待维护';
            default:
                return null;
        }
    }
    add() {
        //变更申请
        this.title = '变更申请';
        setTimeout(() => {
            this.addOrEddit.show();
        }, 10)
    }
    UpdateOrLook(row, type) {
        this.rowdata = row;
        if (type == 1) {
            //修改
            this.title = '变更修改';
            setTimeout(() => {
                this.addOrEddit.show();
            }, 10);
        } else {
            //查看
            this.title = '变更查看';
            setTimeout(() => {
                this.addOrEddit.show();
            }, 10);
        }
    }
    reset() {
        this.model = undefined;
        this.senTime = undefined;
        this.changeType = undefined;
        this.lotNum = undefined;
    }
    delete(row) {
        this.message.confirm(
            '确认删除这条数据吗',
            (isConfirmed) => {
                if (isConfirmed) {
                    if (this.saveFlag) {
                        this.saveFlag = false;
                        this._bomChangeServiceProxy
                            .deleBomNode(row.id)
                            .subscribe((result) => {
                                this.saveFlag = true;
                                if (result.code == 0) {
                                    this.getTableList();
                                    this._messageService.success('删除成功');
                                } else {
                                    this._messageService.error(result.message)
                                }
                            });
                    }
                }
            }
        );
    }
    look(row) {
        this.rowdata = row;
        //履历 
        setTimeout(() => {
            this.ShowResume.show()
            this.ShowResume.getTableList()
        }, 20)
    }
    getTableList(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this._bomChangeServiceProxy.getBomChangeContent(
            this.lotNum,
            this.model,
            this.senTime,
            this.changeType,
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event)
        ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
            this.primengTableHelper.totalRecordsCount = result.totalCount;
            this.primengTableHelper.records = result.items;
            this.primengTableHelper.hideLoadingIndicator();
        });
    }
}
